
#include "Channel.h"
#include "RequestConnect.h"
#include "RequestSync.h"
#include "RequestGet.h"

using namespace Engine;

class CClientRequestAllocator : public CRequestAllocator {

public :
	virtual boost::shared_ptr<CRequest> alloc(std::string& cmd, boost::shared_ptr<std::istream> is) {
		if(cmd == COMMAND_GET) {
			return RequestRef(new CRequestGet(is));
		}
		return boost::shared_ptr<CRequest>();
	}

	virtual boost::shared_ptr<CRequest> alloc(std::string& cmd, boost::asio::streambuf& data) {
		if(cmd == COMMAND_CONNECT) {
			return RequestRef(new CRequestConnect(data));
		}
		else
		if(cmd == COMMAND_SYNC) {
			return RequestRef(new CRequestSync(data));
		}

		return boost::shared_ptr<CRequest>();
	}
};

CChannel::CChannel() : mRequestAllocator(new CClientRequestAllocator())
{
}

